const KoaRouter = require('koa-router')
const HttpClient = require('../util/HttpClient')
const Template = require('../util/Template')

const router = new KoaRouter();
const modules = require('../../modules');
// router.get('/linkc/goods', async ctx => {
//   let script = ['/linkc.goods.js'];
//   let modConfig = modules['linkc.goods'];
//   let reqHeaders = ctx.request.headers;
//   let result = await HttpClient.request('/linkc/goods', 'get', null, {
//     headers: reqHeaders
//   });
//   let body = result.body;
//   ctx.body = await Template.renderWithHtml('商品设置', body, script, modConfig.template, ctx)
// });
router.get('/linkc/order/list', async ctx => {
  let script = ['/linkc.order.list.js'];
  let modConfig = modules['linkc.order.list'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/linkc/order/list', 'get', null, {
    headers: reqHeaders
  });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('订单管理', body, script, modConfig.template, ctx)
});
router.get('/linkc/order/detail', async ctx => {
  let script = ['/linkc.order.detail.js'];
  let modConfig = modules['linkc.order.detail'];
  let reqHeaders = ctx.request.headers;
  let result = await HttpClient.request('/linkc/order/detail', 'get', null, {
    headers: reqHeaders
  });
  let body = result.body;
  ctx.body = await Template.renderWithHtml('订单详情', body, script, modConfig.template, ctx)
});

router.get('/linkc/goods/listV2', async ctx => {
  let script = ['/linkc.goods.listV2.js'];
  let modConfig = modules['linkc.goods.listV2'];

  ctx.body = await Template.renderWithHtml('订单管理', {}, script, modConfig.template, ctx)
});

router.get('/linkc/goods/detailV2', async ctx => {
  let script = ['/linkc.goods.detailV2.js'];
  let modConfig = modules['linkc.goods.detailV2'];

  ctx.body = await Template.renderWithHtml('订单详情', {}, script, modConfig.template, ctx)
});

router.get('/linkc/goods/list', async ctx => {
  let script = ['/linkc.goods.list.js'];
  let modConfig = modules['linkc.goods.list'];

  ctx.body = await Template.renderWithHtml('商品管理', {}, script, modConfig.template, ctx)
});

router.get('/linkc/goods/detail', async ctx => {
  let script = ['/linkc.goods.detail.js'];
  let modConfig = modules['linkc.goods.detail'];

  ctx.body = await Template.renderWithHtml('商品详情', {}, script, modConfig.template, ctx)
});

router.get('/linkc/goods/edit', async ctx => {
  let script = ['/linkc.goods.edit.js'];
  let modConfig = modules['linkc.goods.edit'];

  ctx.body = await Template.renderWithHtml('编辑商品', {}, script, modConfig.template, ctx)
});

router.get('/linkc/goods/preview', async ctx => {
  let script = ['/linkc.goods.preview.js'];
  let modConfig = modules['linkc.goods.preview'];

  ctx.body = await Template.renderWithHtml('商品预览', {}, script, modConfig.template, ctx)
});

module.exports = router;
